/*
 * @Author: 
 * @Date: 2024-05-19 10:11:24
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2024-05-28 16:59:42
 * @Description: 
 */
import { Provide , Config } from '@midwayjs/core';
import { Ipage, IGraph, IAlgorithmParams } from '../interface';
import {M1Product } from '../entity/module1.entity';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, Like } from 'typeorm';

@Provide()
export class M1ModuleService {
    @InjectEntityModel(M1Product)
    M1ProductModel: Repository<M1Product>;

    async getProducts(params: Ipage) {
        const [result, total] = await this.M1ProductModel.findAndCount({
            where: { productName: Like(`%${params.keyword ? params.keyword : ''}%`) },
            skip: (params.page_index - 1) * params.page_size,
            take: params.page_size,
            order: { createDate: 'DESC' },
          });
          return {
            succes: true,
            data: result,
            total,
            message: '成功',
          };
    }
    async deleteProduct(id:number){
      const product = await this.M1ProductModel.findOne({
        where: {
          id,
        },
      });
      let result = await this.M1ProductModel.remove(product);
      return {
        succes: true,
        data: result,
        message: '删除成功',
      };
    }
}